
import time

from Python_Uiautomator_Auto.utils.device import DeviceManager
from Python_Uiautomator_Auto.pages.home_page import HomePage
#
# dm = DeviceManager()
# d = dm.get_device()
# dm.launch_app("com.android.settings")
#
# home = HomePage(d)
# try:
#     home.verify_bluetooth()
#     home.click_item_name("蓝牙")
#     time.sleep(3)
#     switch = home.verify_status_switch()
#     # assert switch.exists, "未找到蓝牙开关元素"
#     is_checked = switch.info.get('checked')
#     print(f"蓝牙开关状态: {is_checked}")
#     # assert is_checked == True, "蓝牙开关未开启"
# finally:
#     dm.close_app("com.android.settings")


def check_bluetooth_status():
    try:
        # 使用XPath定位蓝牙开关（根据图片中的完整路径）
        # bluetooth_switch = d.xpath(
        #     '//*[@resource-id="com.android.settings:id/recycler_view"]'
        #     '/android.view.ViewGroup[1]/android.widget.LinearLayout[1]'
        # ).get()

        dm = DeviceManager()
        d = dm.get_device()
        dm.launch_app("com.android.settings")

        home = HomePage(d)
        home.click_item_name("蓝牙")
        bluetooth_switch = d.xpath('//*[@resource-id="com.android.settings:id/recycler_view"]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]').get()

        # 获取元素的checked属性值
        is_checked = bluetooth_switch.info.get('checked', False)

        if is_checked:
            print("✅ 蓝牙开关状态: 已开启")
            return True
        else:
            print("🔴 蓝牙开关状态: 已关闭")
            return False

    except Exception as e:
        print(f"❌ 验证失败: {str(e)}")
        return False


# 调用验证函数
check_bluetooth_status()












